import React, { useState, useEffect } from "react";
// import { connect } from "react-redux";
// import { actions } from "./_index";
import Unit from "../../unit";
import { Pagination } from "antd";

const App = () => {
  const [pageData, setData] = useState([]);
  const [curr, setCurr] = useState({
    current: 1,
    total: 10,
  });
  const getData = (page = 1, size = 10) => {
    // console.log(page, size);
    const ajaxCfg = {
      page_number: page,
      page_size: size,
    };
    Unit.getApi2("home/mediareports", ajaxCfg, {}).then((res) => {
      if (res.data.code === 200) {
        setData([...res.data.data]);
        setCurr({ current: page, total: res.data.total });
      }
    });
  };
  const lists = () => {
    return pageData.map((val, index) => {
      return <li key={index}>{val.main_title}</li>;
    });
  };
  useEffect(() => {
    setTimeout(() => {
      getData();
    }, 2000);
  }, []);
  return (
    <div>
      {pageData.length > 0 ? (
        <ul>
          {lists()}
          <Pagination
            defaultCurrent={curr.current}
            total={curr.total}
            onChange={getData}
          />
        </ul>
      ) : (
        <div>正在加载...</div>
      )}
    </div>
  );
};
// const mapStateToProps = (state) => {
//   console.log(state.page);
//   return {
//     page: state.page,
//   };
// };
// const mapDispatchToProps = (dispatch, ownProps) => {
//   return {
//     getPdd: (text, ajaxCfg, prevData) =>
//       dispatch(actions.getPdd(text, ajaxCfg, dispatch, prevData)),
//   };
// };
// export default connect(mapStateToProps, mapDispatchToProps)(App);
export default App;
